package cn.ljy.uem.web.action.frontend.mobile.course;

import cn.ljy.authority.config.security.TokenUtil;
import cn.ljy.authority.model.SysUser;
import cn.ljy.authority.service.SysUserTokenFrontendService;
import cn.ljy.authority.web.controller.backstage.BaseController;
import cn.ljy.common.model.result.ResponseData;
import cn.ljy.uem.model.SchoolStudent;
import cn.ljy.uem.service.SchoolStudentService;
import cn.ljy.uem.service.common.CommonSchoolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
@Api(tags = "学生个人课程管理")
@RestController
@RequestMapping(value = "/api/mobile/schoolStudentCourse")
public class SchoolStudentCoursesController extends BaseController {
    @Autowired
    private SysUserTokenFrontendService sysUserTokenFrontendService;
    @Autowired
    private CommonSchoolService commonSchoolService;
    @Autowired
    private SchoolStudentService schoolStudentService;

    @ApiOperation(value = "读取学生个人拥有的课程列表")
    @GetMapping("/CoursesForStudent")
    public ResponseData CoursesForTeachers(){
        String token= TokenUtil.getAppToken();//读取前台token的值
        //获取登录账户信息
        SysUser user=sysUserTokenFrontendService.getUserFromToken(token);
        //获取登录账户对应的学生信息
        SchoolStudent student=commonSchoolService.getStudent(user);
        return  ResponseData.success(schoolStudentService.getCoursesOfStudent(student));
    }
}
